/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cn.ekuma.impexp.processor;

import cn.ekuma.impexp.ImpExpManager;
import cn.ekuma.impexp.model.AbstractImpExpTableDefinition;
import cn.ekuma.impexp.ImpExpTableProcessor;
import cn.ekuma.impexp.model.ImpExpRowDefinition;
import com.openbravo.data.basic.BasicException;
import com.openbravo.format.Formats;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *此类主要用于把导入字符串对象，转化为相应的java对象，以便于后其的处理
 * @author Administrator
 */
public class ImportObjectConverProcessor extends ImpExpTableProcessor{

    public ImportObjectConverProcessor(ImpExpManager manager) {
        super(manager);
    }

    @Override
    public void process(AbstractImpExpTableDefinition table) {
           Formats[] fieldFormats=table.getBaseTable().getFieldformat();
           int[] fieldIndex=table.getListFieldIndexs();
           ImpExpRowDefinition row;
           int rowCount=table.getRowCount();
           for(int rowindex=0;rowindex<rowCount;rowindex++){
        	    row=table.getRow(rowindex);
        	    Object[] trusDate=table.getData(rowindex);
                Object[] data1=new Object[trusDate.length];
                for(int i=0;i<fieldIndex.length;i++){
                	int realColumn=fieldIndex[i];
                	if(trusDate[i]!=null&&!(trusDate[i] instanceof String)){
                		data1[i]=trusDate[i];
                		continue;
                	}
                	try {
                        data1[i] = fieldFormats[realColumn].parseValue((String) trusDate[i]);
                    } catch (BasicException ex) {
                 	   ex.printStackTrace();
                       Logger.getLogger(ImportObjectConverProcessor.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
                row.setDatas(data1);
           }
    }
}
